// pages/teamDetails/teamDetails.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    teamInfo:{},
    imgpath:'',
    team_member: [],
    httpPath: app.globalData.imagePath,
    team_id:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var _key = wx.getStorageSync("token");
    that.setData({
      team_id: options.teamid
    })
    wx.showLoading({
      title: '数据加载中'
    })
    //球队信息
    wx.request({
      url: app.globalData.httpsPath + '/team/show',
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      data: {
        team_id: options.teamid
      },
      //请求后台数据成功  
      success: function (res) {
        wx.hideLoading();
        //将获取到的json数据，存在名字叫zhihu的这个数组中
        that.setData({
          teamInfo: res.data.data,
          imgpath: app.globalData.imagePath + res.data.data.logo
        })
      }
    })
    //球队队员
    wx.request({
      url: app.globalData.httpsPath + '/team/users',
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      data: {
        token: _key,
        team_id: options.teamid
      },
      //请求后台数据成功  
      success: function (res) {
        var team_member = res.data.data;
        that.setData({
          team_member: team_member
        })
      }
    })
  },
  //队员管理
  playerManage: function () {
    wx.navigateTo({
      url: '../playerReview/playerReview',
    })
  },
  //安排阵容
  lineUpBtn:function(){
    var teamId = this.data.team_id;
    wx.navigateTo({
      url: '../gameLineup/gameLineup?teamid=' + teamId,
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options) {
    var that = this;
    if (options.from === 'button') {
      // 来自页面内转发按钮
      console.log(options.target)
    }
    return {
      title: '邀请加入',
      imageUrl:'../../images/share_bg.png',
      path: '/pages/teamDetailsPlayer/teamDetailsPlayer?teamid=' + that.data.team_id
    }
  }
})